
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Csla.Validation;

namespace SariturIntranetLibrary.Atas
{
    [Serializable()]
    public class AtaDeReuniaoChildInfo : Csla.ReadOnlyBase<AtaDeReuniaoChildInfo>
    {

        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private string _titulo = string.Empty;

        private SmartDate _dataOcorrido = new SmartDate(false);

        private SmartDate _dataCadastro = new SmartDate(false);

        private string _descricao = string.Empty;

        private string _observacoes = string.Empty;

        private Guid _cadastradoPorId = Guid.Empty;

        private Guid _anexoId = Guid.Empty;

        [System.ComponentModel.DataObjectField(true, false)]
        public Guid Id
        {
            get
            {
                CanReadProperty("Id", true);
                return _id;
            }
        }

        public string Titulo
        {
            get
            {
                CanReadProperty("Titulo", true);
                return _titulo;
            }
        }

        public string TituloAbreviado
        {
            get
            {
                CanReadProperty("TituloAbreviado", true);
                if (_titulo.Length < 35)
                    return _titulo;
                return _titulo.Substring(0, 34) + "(...)";
            }
        }

        public DateTime DataOcorrido
        {
            get
            {
                CanReadProperty("DataOcorrido", true);
                return _dataOcorrido.Date;
            }
        }

        public string DataOcorridoString
        {
            get
            {
                CanReadProperty("DataOcorridoString", true);
                return _dataOcorrido.Text;
            }
        }

        public DateTime DataCadastro
        {
            get
            {
                CanReadProperty("DataCadastro", true);
                return _dataCadastro.Date;
            }
        }

        public string DataCadastroString
        {
            get
            {
                CanReadProperty("DataCadastroString", true);
                return _dataCadastro.Text;
            }
        }

        public string Descricao
        {
            get
            {
                CanReadProperty("Descricao", true);
                return _descricao;
            }
        }

        public string Observacoes
        {
            get
            {
                CanReadProperty("Observacoes", true);
                return _observacoes;
            }
        }

        public Guid CadastradoPorId
        {
            get
            {
                CanReadProperty("CadastradoPorId", true);
                return _cadastradoPorId;
            }
        }

        public Guid AnexoId
        {
            get
            {
                CanReadProperty("AnexoId", true);
                return _anexoId;
            }
        }

        protected override object GetIdValue()
        {
            return _id;
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in AtaDeReuniaoChildInfo
            //AuthorizationRules.AllowRead("Id", "AtaDeReuniaoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Titulo", "AtaDeReuniaoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("DataOcorrido", "AtaDeReuniaoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("DataOcorridoString", "AtaDeReuniaoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("DataCadastro", "AtaDeReuniaoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("DataCadastroString", "AtaDeReuniaoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Descricao", "AtaDeReuniaoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Observacoes", "AtaDeReuniaoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("CadastradoPorId", "AtaDeReuniaoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("AnexoId", "AtaDeReuniaoChildInfoReadGroup");

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static AtaDeReuniaoChildInfo GetAtaDeReuniaoChildInfo(SafeDataReader dr)
        {
            return new AtaDeReuniaoChildInfo(dr);
        }

        private AtaDeReuniaoChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods


        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = dr.GetGuid("Id");
            _titulo = dr.GetString("Titulo");
            _dataOcorrido = dr.GetSmartDate("DataOcorrido", _dataOcorrido.EmptyIsMin);
            _dataCadastro = dr.GetSmartDate("DataCadastro", _dataCadastro.EmptyIsMin);
            _descricao = dr.GetString("Descricao");
            _observacoes = dr.GetString("Observacoes");
            _cadastradoPorId = dr.GetGuid("CadastradoPorId");
            _anexoId = dr.GetGuid("AnexoId");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
